import 'package:dsp48_v10/src/search/search_view.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';

import '../../common/bg_page.dart';
import '../../tool/assets.dart';
import 'home_left.dart';
import 'home_right.dart';

class MyHome extends HomePageDelegate {
  @override
  Widget? get endDrawer => const SearchView();

  @override
  GlobalKey<ScaffoldState>? createrGlobalKey() {
    return GlobalKey<ScaffoldState>();
  }

  @override
  void onInit(BuildContext context) {
    globalController.loadLocal();
  }

  Future<void> _action(BuildContext context, String tag, dynamic value) async {
    switch (tag) {
      case 'SEARCH':
        scaffoldKey?.currentState?.openEndDrawer();
        break;
      case 'CUSTOM NAME':
        scaffoldKey?.currentState?.openEndDrawer();
        break;
      case 'CHANGE PWASSORD':
        controller.changePassword(context);
        break;
      case 'LOAD FROM FILE':
        String data = await controller.loadDSPFile(context);
        // globalController.showLogLoading(context, data);
        break;
      case '静音':
        controller.allMute();
        break;
      default:
    }
    print("你选择了: $tag");
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: MediaQuery.of(context).size.height, // 关键！
      child: Stack(
        children: [
          Positioned.fill(child: BgPage(bg: assets.B6, logo: assets.L6)),
          Positioned.fill(
            child: Padding(
              padding: const EdgeInsets.only(left: 10, top: 10, bottom: 10, right: 10),
              child: Row(
                children: [
                  //左边部分
                  const Expanded(child: HomeLeft()),

                  const SizedBox(width: 10),

                  ///右边部分

                  Flexible(flex: 3, child: HomeRight(onClick: (tag, value) => _action(context, tag, value)))
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
